from CustomGuiItems.MyDockWidget import MyDockWidget;
from GraphSettings.GraphGuiSettings.SettingsPane.Settings_General import Settings_General;
from GraphSettings.GraphGuiSettings.SettingsPane.Settings_InfoDisplay import Settings_InfoDisplay;
from GraphSettings.GraphGuiSettings.SettingsPane.Settings_ShapeStyle import Settings_ShapeStyle;
from GraphSettings.GraphGuiSettings.SettingsPane.Settings_StatusType import Settings_StatusType;
from GraphSettings.GraphGuiSettings.SettingsPane.Settings_Align import Settings_Align;
from PyQt4 import QtGui, QtCore; #@UnusedImport

class GraphSettingsPane(QtCore.QObject):    
    def __init__(self, parent):
        super(GraphSettingsPane, self).__init__();
        self.parent = parent;
        self.mainWin = parent.mainWin;
        self.graphScene = parent.graphScene;
        self.dataView = self.parent.dataContainer.dataView;
        self.myDockWidget = MyDockWidget("Graph Settings", self.parent);
        self.mainWin.addDockWidget(QtCore.Qt.RightDockWidgetArea, self.myDockWidget);
        self.createGroupWidgets();
        self.createGraphSettings();
        self.myDockWidget.setWidget(self.qScroll);
        self.myDockWidget.setMinimumWidth(260);
#        self.myDockWidget.setVisible(False);
        
    def onGrpStatusClick(self, bOn):
        self.settings_StatusType.qWidget.setVisible(bOn);
        self.resizeWidget(self.settings_StatusType, self.groupStatus, bOn);
        
    def onGrpShapeClick(self, bOn):
        self.settings_ShapeStyle.qWidget.setVisible(bOn);
        self.resizeWidget(self.settings_ShapeStyle, self.groupShape, bOn);
        
    def onGrpInfoClick(self, bOn):
        self.settings_InfoDisplay.qWidget.setVisible(bOn);
        self.resizeWidget(self.settings_InfoDisplay, self.groupInfo, bOn);
        
    def onGrpGralClick(self, bOn):
        self.settings_General.qWidget.setVisible(bOn);
        self.resizeWidget(self.settings_General, self.groupGral, bOn);
        
    def onGrpAlignClick(self, bOn):
        self.settings_Align.qWidget.setVisible(bOn);
        self.resizeWidget(self.settings_Align, self.groupAlign, bOn);
        
    def onGrpMazeClick(self, bOn):
        self.settings_Maze.qWidget.setVisible(bOn);
        self.resizeWidget(self.settings_Maze, self.groupMaze, bOn);
        
    def onGrpMazeProbsClick(self, bOn):
        self.settings_MazeProbs.qWidget.setVisible(bOn);
        self.resizeWidget(self.settings_MazeProbs, self.groupMazeProbs, bOn);

    def resizeWidget(self, obj, objGrp, bOn):
#        print obj.qWidget.size();
        if bOn:
            nHeight = self.qWidget.minimumHeight() + self.aHeights[obj];
            nGrpHeight = self.aHeights[obj]+30;
        else:
            nHeight = self.qWidget.minimumHeight() - self.aHeights[obj];
            nGrpHeight = 15;
        self.qWidget.setMinimumHeight(nHeight);
        self.qWidget.setMaximumHeight(nHeight);
        objGrp.setMaximumHeight(nGrpHeight);
        
    def updateSelectedGraphSettings(self):
        self.settings_ShapeStyle.updateSelectedSettings();
        self.settings_InfoDisplay.updateSelectedSettings();
        self.settings_General.updateSelectedSettings();
            
        
    def createGraphSettings(self):
        self.settings_StatusType = Settings_StatusType(self.parent);
        self.settings_ShapeStyle = Settings_ShapeStyle(self.parent);
        self.settings_InfoDisplay = Settings_InfoDisplay(self.parent);
        self.settings_General = Settings_General(self.parent);
        self.settings_Align = Settings_Align(self.parent);
        self.settings_Maze = self.dataView.mazeStInput;
        self.settings_MazeProbs = self.dataView.mazeProbs;
        self.groupStatus.setLayout(self.settings_StatusType.vBoxMain);
        self.groupShape.setLayout(self.settings_ShapeStyle.vBoxMain);
        self.groupInfo.setLayout(self.settings_InfoDisplay.vBoxMain);
        self.groupGral.setLayout(self.settings_General.vBoxMain);
        self.groupAlign.setLayout(self.settings_Align.vBoxMain);
        self.groupMaze.setLayout(self.settings_Maze.vBoxMain);
        self.groupMazeProbs.setLayout(self.settings_MazeProbs.vBoxMain);
        self.settings_StatusType.qWidget.setVisible(False);
        self.settings_ShapeStyle.qWidget.setVisible(False);
        self.settings_InfoDisplay.qWidget.setVisible(False);
        self.settings_General.qWidget.setVisible(False);
        self.settings_Align.qWidget.setVisible(False);
        self.settings_Maze.qWidget.setVisible(False);
        self.settings_MazeProbs.qWidget.setVisible(False);
        self.aHeights = {};
        self.aHeights[self.settings_StatusType] = 184;
        self.aHeights[self.settings_ShapeStyle] = 64;
        self.aHeights[self.settings_InfoDisplay] = 90;
        self.aHeights[self.settings_General] = 206;
        self.aHeights[self.settings_Align] = 207;
        self.aHeights[self.settings_Maze] = 140;
        self.aHeights[self.settings_MazeProbs] = 140;
        
    def createGroupWidgets(self):
        self.groupStatus = QtGui.QGroupBox("Status Type", self.mainWin);
        self.groupShape = QtGui.QGroupBox("Shape Style", self.mainWin);
        self.groupInfo = QtGui.QGroupBox("Info Display", self.mainWin);
        self.groupGral = QtGui.QGroupBox("General Settings", self.mainWin);
        self.groupAlign = QtGui.QGroupBox("Align Nodes", self.mainWin);
        self.groupMaze = QtGui.QGroupBox("Maze Edit", self.mainWin);
        self.groupMazeProbs = QtGui.QGroupBox("Maze Generate Probs", self.mainWin);
        self.aGroups = [];
        self.aGroups.append(self.groupStatus);
        self.aGroups.append(self.groupShape);
        self.aGroups.append(self.groupInfo);
        self.aGroups.append(self.groupGral);
        self.aGroups.append(self.groupAlign);
        self.aGroups.append(self.groupMaze);
        self.aGroups.append(self.groupMazeProbs);
        for grp in self.aGroups:
            grp.setCheckable(True);
            grp.setChecked(False);
            grp.setFlat(True);
            grp.setMaximumHeight(15);
#        self.groupStatus.setCheckable(True);
#        self.groupShape.setCheckable(True);
#        self.groupInfo.setCheckable(True);
#        self.groupGral.setCheckable(True);
#        self.groupAlign.setCheckable(True);
#        self.groupMaze.setCheckable(True);
#        self.groupStatus.setChecked(False);
#        self.groupShape.setChecked(False);
#        self.groupInfo.setChecked(False);
#        self.groupGral.setChecked(False);
#        self.groupAlign.setChecked(False);
#        self.groupMaze.setChecked(False);
        self.groupStatus.connect(self.groupStatus, QtCore.SIGNAL("toggled(bool)"), self.onGrpStatusClick);
        self.groupShape.connect(self.groupShape, QtCore.SIGNAL("toggled(bool)"), self.onGrpShapeClick);
        self.groupInfo.connect(self.groupInfo, QtCore.SIGNAL("toggled(bool)"), self.onGrpInfoClick);
        self.groupGral.connect(self.groupGral, QtCore.SIGNAL("toggled(bool)"), self.onGrpGralClick);
        self.groupAlign.connect(self.groupAlign, QtCore.SIGNAL("toggled(bool)"), self.onGrpAlignClick);
        self.groupMaze.connect(self.groupMaze, QtCore.SIGNAL("toggled(bool)"), self.onGrpMazeClick);
        self.groupMazeProbs.connect(self.groupMazeProbs, QtCore.SIGNAL("toggled(bool)"), self.onGrpMazeProbsClick);
#        self.groupStatus.setFlat(True);
#        self.groupShape.setFlat(True);
#        self.groupInfo.setFlat(True);
#        self.groupGral.setFlat(True);
#        self.groupAlign.setFlat(True);
#        self.groupStatus.setMaximumHeight(15);
#        self.groupShape.setMaximumHeight(15);
#        self.groupInfo.setMaximumHeight(15);
#        self.groupGral.setMaximumHeight(15);
#        self.groupAlign.setMaximumHeight(15);
        
        self.vBoxLayout = QtGui.QVBoxLayout();
        self.vBoxLayout.addWidget(self.groupGral);
        self.vBoxLayout.addWidget(self.groupInfo);
        self.vBoxLayout.addWidget(self.groupMazeProbs);
        self.vBoxLayout.addWidget(self.groupMaze);
        self.vBoxLayout.addWidget(self.groupShape);
        self.vBoxLayout.addWidget(self.groupAlign);
        self.vBoxLayout.addWidget(self.groupStatus);
        self.vBoxLayout.addStretch(1);        
        self.qWidget = QtGui.QWidget(self.mainWin);
        self.qWidget.setLayout(self.vBoxLayout);
        self.qWidget.setMinimumHeight(300);
        self.qWidget.setMaximumHeight(300);
        self.qWidget.setMinimumWidth(240);
#        self.qWidget.setBackgroundRole(QtGui.QPalette.Dark);
        self.qScroll = QtGui.QScrollArea(self.mainWin);
        self.qScroll.setWidget(self.qWidget);
    
        
    def getDataSettings(self):
        aDataSettings = [];
        aDataSettings.append(self.settings_ShapeStyle.getDataSettings());
        aDataSettings.append(self.settings_InfoDisplay.getDataSettings());
        aDataSettings.append(self.settings_General.getDataSettings());
        return aDataSettings;
        
    def setDataSettings(self, aDataSettings):
        self.settings_ShapeStyle.setDataSettings(aDataSettings[0]);
        self.settings_InfoDisplay.setDataSettings(aDataSettings[1]);
        self.settings_General.setDataSettings(aDataSettings[2]);
